package com.czy.blog.entity;

import java.io.Serializable;
import java.util.Set;

import javax.persistence.Access;
import javax.persistence.AccessType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.hibernate.annotations.GenericGenerator;

@Entity
@Table(name="sys_function")
public class Function implements Serializable
{
	private static final long serialVersionUID = -6781736874719042781L;
	
	@Id
	@GeneratedValue(generator = "system-uuid")
	@GenericGenerator(name = "system-uuid", strategy = "uuid.hex")
	@Column(name = "ID")
	@Access(AccessType.PROPERTY)
	private String id;
	
	@Column(name="FUNC_CODE")
	private String funcCode;
	
	@Column(name="FUNC_Name")
	private String funcName;
	
	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name = "MENU_ID")
	private Menu menu;
	
	@ManyToMany(fetch=FetchType.LAZY,mappedBy="funcs")
	private Set<Role> roles;
	
	@Override
	public boolean equals(Object obj)
	{
		if(obj instanceof Function){
			Function func = (Function)obj;
			if(func.getId().equals(this.getId())){
				return true;
			}
		}
		
		return false;
	}
	
	@Override
	public int hashCode()
	{
		return this.id.hashCode();
	}

	public String getId()
	{
		return id;
	}

	public void setId(String id)
	{
		this.id = id;
	}

	public String getFuncCode()
	{
		return funcCode;
	}

	public void setFuncCode(String funcCode)
	{
		this.funcCode = funcCode;
	}

	public Menu getMenu()
	{
		return menu;
	}

	public void setMenu(Menu menu)
	{
		this.menu = menu;
	}

	public Set<Role> getRoles()
	{
		return roles;
	}

	public void setRoles(Set<Role> roles)
	{
		this.roles = roles;
	}

	public String getFuncName()
	{
		return funcName;
	}

	public void setFuncName(String funcName)
	{
		this.funcName = funcName;
	}
}
